package com.yzc.main;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Document;

import com.yzc.util.ArgUtils;
import com.yzc.util.DocumentFactory;
import com.yzc.util.ModUtils;
import com.yzc.util.XmlPath;

/**
 * 命令 ： mod jdk=1.7 servlet=3.0
 * 		for (String arg : args) {
			String[] s = arg.split("=");
			for (String string : s) {
				System.out.println(string);
			}
		}
		
		for (Map.Entry<String, String> arg : argsMap.entrySet()) {
			System.out.println(arg.getKey() + "---" + arg.getValue());
		}
 * 
 * */

public class Mod {
	
	private static Map<String,String> argsMap = new HashMap<String,String>();
	
	public static void init(String[] args){
		ArgUtils.fillargsMapfromArgs(argsMap, args);
		XmlPath.fillXmlPathString(argsMap.get("path"));
	}
	
	public static void main(String[] args) {
		init(args);
		
		Document settingDocument = DocumentFactory.getDocument(XmlPath.setting);
		ModUtils.modSetting(argsMap, settingDocument, XmlPath.setting);

		Document pomDocument = DocumentFactory.getDocument(XmlPath.pom);
		ModUtils.modPom(argsMap, pomDocument, XmlPath.pom);
		
		try {
			ModUtils.modWeb(XmlPath.web, ArgUtils.getWebFile(argsMap.get("servlet")));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		File srcmainjava = new File(XmlPath.src_main_java);
		File srctestjava = new File(XmlPath.src_test_java);
		srcmainjava.mkdirs();
		srctestjava.mkdirs();
		
	}
}
